package com.drojian.demo2.broadcast.test1;

import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import com.drojian.demo.R;

public class MySendBroadcastActivity extends AppCompatActivity {
    private EditText textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);

        setContentView(R.layout.part2_activity_my_send_broadcast);
        textView = findViewById(R.id.broadcast_text);

    }

    public void send_broadcast(View view) {
        Intent intent = new Intent(Constants.ACTION_SEND_MSG);//将要发送广播的值传入
        //Android8.0以上版本接收广播需要加ComponentName俩参数为静态广播的包名和类名，因为Android8在静态广播的使用上做了一些限制
        intent.setComponent(new ComponentName(this,"com.drojian.demo2.broadcast.test1.MyBroadcastReceiver"));
        intent.putExtra(Constants.KEY_DATA,"输入的广播消息为："+textView.getText());
        sendOrderedBroadcast(intent,null);//发送有序广播
        Log.e("leo", "onClick: 广播已经发出");
    }
}
